package controller

import (
	"data-system/config"
	"data-system/models"
	"fmt"
	"log"

	"github.com/gin-gonic/gin"
)

func GetConfig(c *gin.Context) {
	c.JSON(models.OkData(config.GetConfig()))
}

func SetConfig(c *gin.Context) {
	req := struct {
		AssetDir  string `json:"assetDir"`
		ConfigDir string `json:"configDir"`
		PubDir    string `json:"pubDir"`
		Project   string `json:"project"`
	}{}
	if err := c.Bind(&req); err != nil {
		log.Println(fmt.Errorf("参数解析异常,%v", err))
		c.JSON(models.FailData(err.Error()))
		return
	}
	config.SetConfig(&req.AssetDir, &req.ConfigDir, &req.PubDir, &req.Project)
	c.JSON(models.Ok())
}
